package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.base.BaseController;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {
    @Reference
    private DictService dictService;
    @RequestMapping
    public String index (){
        return "dict/index";
    }
    @RequestMapping("/findZnodes")
    @ResponseBody //不进行转发和重定向，而是直接返回数据（Ajax）
    public Result findZnodes(@RequestParam(defaultValue = "0") Long id){
        //获取指定父id的子字典列表
        List<Map<String, Object>> znodes = this.dictService.findZnodes(id);
        //安装统一的格式返回数据
        return Result.ok(znodes);
    }
    @RequestMapping("/findListByParentId/{parentId}")
    @ResponseBody
    public Result<List<Dict>> findListByParentId(@PathVariable Long parentId) { //110000
        List<Dict> dictList = this.dictService.findListByParentId(parentId);
        return Result.ok(dictList);
    }
    @RequestMapping("/findListByDictCode/{dictCode}")
    @ResponseBody
    public Result<List<Dict>> findListByDictCode(@PathVariable String dictCode) { //beijing
        List<Dict> dictList = this.dictService.findListByDictCode(dictCode);
        return Result.ok(dictList);
    }
}
